USE [ServerMonitor]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KillBlockHeader]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[KillBlockHeader]
GO
USE [ServerMonitor]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[KillBlockHeader]
AS
BEGIN
  SET NOCOUNT ON
  SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  
  DECLARE @spid SMALLINT
  DECLARE SPIDCur CURSOR
  FOR
    SELECT spid FROM master..sysprocesses
    WHERE spid IN (SELECT blocked FROM master..sysprocesses
    WHERE blocked != 0) AND spid > 50 AND blocked = 0
  OPEN SPIDCur
  FETCH NEXT FROM SPIDCur INTO @spid
  WHILE @@FETCH_STATUS = 0
  BEGIN
    EXEC ('KILL ' + @spid)
    PRINT 'KILL ' + CONVERT(VARCHAR(10),@spid)
    
    FETCH NEXT FROM SPIDCur INTO @spid
  END
  CLOSE SPIDCur
  DEALLOCATE SPIDCur
  
  SET NOCOUNT ON
END

GO


